Dynamically loading patterns

With the advent of TEX 3.0 it has become possible to build a format with more than one hyphenation pattern preloaded. The core of the babel system provides code, to be executed by iniTEX only, to dynamically load hyphenation patterns. The only restriction is that the implementation of TEX that you use has to have rather high settings of trie_size and trie_op_size to actually load several hyphenation patterns.

For the purpose of dynamically loading hyphenation patterns a `configuration file' has to be introduced. This file will be read by iniTEX. Each line should contain either a comment, nothing or the name of a language and the name of the file that contains the hyphenation patterns for that language. In figure [*] an example of such a file, instructing iniTEX to load patterns for three languages, English, Dutch and German.

Figure: An example configuration file
\begin{figure*}\begin{verbatim}% File : language.dat
% Purpose : tell iniTeX w...
...sdutch hyphen.dutch % Nederlands
german hyphen.ger\end{verbatim}
\end{figure*}

The configurationfile will be read line by line using TEX's \read primitive. Because the name of a file might be followed by a space-token and comment (as in the example) a macro to process each line is needed. The definition of this macro, \process@language, can be found in figure [*]. As can be seen in the definition of this macro, its second argument always has to be followed by a space-token. The effect of this is that any trailing spaces are removed.

Figure: The definition of \process@language.
\begin{figure*}\begin{verbatim}\def\process@language ...
The macro strips all spaces following its arguments. It's first argument is used to define \l@ :〉!:}language. The macro \addlanguage is basically a non-outer version of the plain TEX macro \newlanguage. The second argument of \process@language is the name of the file containing the hyphenation patterns. Before the file can be read, the register \language has to updated.

The configuration file is read in a \loop (see figure [*]). When a record is read from the input file a check is done whether the record was empty. If it was not, a space token is added to the end of the string of tokens read. The reason for this is that we have to be sure there always is at least one space token present. When that has been taken care of the data just read can be processed. The last thing to do is to check the status of the input file, in order to decide whether TEX has to continue processing the \loop. When all patterns have been processed the value of \language is restored.

Figure: Reading the configuration file line by line
\begin{figure*}\begin{verbatim}\loop
\read1 to \@config@line
\ifx\@config@li...
...\ifeof1 \@morefalse \fi
\if@more\repeat
\language=0\end{verbatim}
\end{figure*}